const Sequelize = require('sequelize');
const DB = require("../config/dbconfig");
const triendModel = require('./triend_tab');
const userModel = require('./user_tab');

const triendLikeModel = DB.define('triend_like_tab', {
    like_id: {
      type: Sequelize.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: "点赞id，主键"
    },
    user_id: {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: "用户表外键",
      references: {
        model: 'user_tab',
        key: 'user_id'
      }
    },
    triend_id: {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: "动态表外键",
      references: {
        model: 'triend_tab',
        key: 'triend_id'
      }
    },
    triend_like_time:{
      type:Sequelize.DATE,
      allowNull:true,
      comment:"动态点赞时间"
    },
    is_delete:{
      type:Sequelize.INTEGER(2),
      comment:"是否删除"
    }
  }, {
    Sequelize,
    tableName: 'triend_like_tab',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "like_id" },
        ]
      },
      {
        name: "triend_like",
        using: "BTREE",
        fields: [
          { name: "triend_id" },
        ]
      },
      {
        name: "user_like",
        using: "BTREE",
        fields: [
          { name: "user_id" },
        ]
      },
    ]
  });
// triendLikeModel.belongsTo(triendModel, { foreignKey: 'triend_id' }); // 假设外键字段为 user_id
triendLikeModel.belongsTo(userModel, { foreignKey: 'user_id' });
module.exports = triendLikeModel
